package com.zengqingfa.examples.mybatisplus.enums;


/**
 * 性别枚举
 */
public enum SexEnum {
    MAN(1, "男"),
    WOMEN(2, "女");

    private Integer key;
    private String value;

    SexEnum(Integer key, String value) {
        this.key = key;
        this.value = value;
    }

    public Integer getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    /**
     * 根据key获取枚举
     *
     * @param key
     * @return
     */
    public static SexEnum getEnum(Integer key) {
        SexEnum[] sexEnums = values();
        for (SexEnum sexEnum : sexEnums) {
            if (sexEnum.getKey().equals(key)) {
                return sexEnum;
            }
        }
        return null;
    }
}
